// 在不破坏封装性的前提下，捕获一个对象的内部状态，并在该对象之外保存这个状态。这样以后就可将该对象恢复到保存的状态。

//
class Store {
  content:any
  constructor(content) {
    this.content = content;
  }
  get() {
    return this.content;
  }
}

class StoreList {
  list:any
  constructor() {
    this.list = [];
  }
  addStore(store) {
    this.list.push(store);
  }

  getStore(index) {
    return this.list[index];
  }
}

class Editor {
  content:any
  constructor() {
    this.content = "";
  }

  addContent(content) {
    this.content = content;
  }

  getContent() {
    return this.content;
  }

  addContentToStore() {
    return new Store(this.content);
  }

  getContentFromStore(store) {
    this.content = store?.get();
  }
}

let editor = new Editor();
let storeList = new StoreList();

editor.addContent("111");
// console.log(editor.getContent());
editor.addContent("222");
// console.log(editor.getContent());

storeList.addStore(editor.addContentToStore());
editor.addContent("333");
console.log(editor.getContent());
storeList.addStore(editor.addContentToStore());

//从sotreList中恢复
editor.getContentFromStore(storeList.getStore(0));
console.log(editor.getContent());
editor.getContentFromStore(storeList.getStore(1));
console.log(editor.getContent());

editor.getContentFromStore(storeList.getStore(2));
console.log(editor.getContent());
